package com.search.analysis;

import com.search.FxApplication;
import com.search.entity.SearchContentEntity;
import com.search.utils.OkHttpUtils;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import org.jsoup.Jsoup;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public interface Analysis {
    //获取数据
    String getData(String keyWord);

    //数据提取
    List<Map<String, Object>> extract(String data);

    //数据清洗
    List<SearchContentEntity>  rinse(List<Map<String, Object>> list);

    //数据加工
    List<SearchContentEntity> process(List<SearchContentEntity> list);



    //将结果解为json
   default List<Pane> toVBox(List<SearchContentEntity> list){
       List<Pane> list1 = new ArrayList<>();
       list.stream().parallel().forEach(data->{
           VBox vBox = new VBox();
           Text title = new Text( data.getTitle());
           title.setFont(Font.font(15));
           title.setOnMouseClicked(e -> {
               //打开网页
               FxApplication.hostServices.showDocument(data.getUrl());
           });
           Text text = new Text("描述:"+data.getContent());
           Text time = new Text("时间:"+data.getTime());
           Text source = new Text("来源:"+data.getSource());
           Text author = new Text("作者:"+data.getAuthor());
           vBox.getChildren().addAll(title, text, time, source, author);
           list1.add(vBox);
       });

       return list1;
    };
}
